import YZRequest from './request'
import { TIME_OUT, BASE_URL } from './request/config'
import localCache from 'utils/cache'

export default new YZRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      // 携带token的拦截
      const token = localCache.getCache('token')
      if (token) {
        config.headers = { ...config.headers, Authorization: `Bearer ${token}` }
      }
      return config
    },
    requestInterceptorCatch: (err) => {
      return Promise.reject(err)
    },
    responseInterceptor: (res) => {
      return res
    },
    responseInterceptorCatch: (err) => {
      return Promise.reject(err)
    }
  }
})
